home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c
- Subject: Re: Can't figure this out
- Date: 19 Jan 1996 22:27:54 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan19172754@g7240065.bridge.bst.bls.com>
- References: <31000091.3778302@news.panix.com>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: dm@panix.com's message of Fri, 19 Jan 1996 21:11:43 GMT
-
- In article <31000091.3778302@news.panix.com> dm@panix.com (Dan'l) writes:
-
- : I am learning C and I have not had any problems understanding most
- : concepts I have learned so far. But to date I still can't figure out
- : how the outcome of this program is 15. Somehow one of the B's ends up
- : a three and the other B a 5, or am I so off base that I can't see
- : what's really happening. Can someone please walk me through this
- : one. Thanks Dan'l
-
- : #define A 3
- : #define B A + A
- : #define C B * B
-
- : main()
- : {
- : printf("%d", C);
- : return 0;
- : }
-
- Expanding the #defines you get
-
- #define A 3
- #define B A + A
- #define C B * B
-
- expanding A
-
- #define B 3 + 3
- #define C B * B
-
- expanding B
-
- #define C 3 + 3 * 3 + 3
-
- As '*' has a higher precedence than '+' this is evaluated as
-
- 3 + (3 * 3) + 3
-
- Which is 15.
-
- Regards
-
- -A.
-
-
- --
- | A.Champion |
-